package com.hgd.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletResponseAware;

import com.hgd.client.admin.Admin;
import com.hgd.client.admin.AdminImplDelegate;
import com.hgd.client.admin.AdminImplService;
import com.hgd.client.admin.ManagementStation;
import com.hgd.client.ms.MSImplDelegate;
import com.hgd.client.ms.MSImplService;
import com.opensymphony.xwork2.ActionSupport;
public class AdminAction extends ActionSupport implements ServletResponseAware{
	
	private List<Admin> adminList = new ArrayList<Admin>();
	private List<ManagementStation> stations = new ArrayList<ManagementStation>();
	private Admin admin = new Admin();
	private Integer adminId;
	private AdminImplService service = new AdminImplService();			
	private AdminImplDelegate delegate = service.getAdminImplPort();
	private MSImplService msImplService = new MSImplService();
	private MSImplDelegate msImplDelegate = msImplService.getMSImplPort();
	private javax.servlet.http.HttpServletResponse response;
	private int addFlag;
	private Integer isEnabled;
	/**
	 * 修改用户
	 * @return
	 * @throws Exception
	 */
	public String mod() throws Exception{
		int flag = 0;
		String modResult;
		flag = delegate.adminMod(admin);
		if (flag==1) {	
			modResult = SUCCESS;
		}else{
			modResult = ERROR;
		}
		return modResult;
	}
	/**
	 * 删除用户
	 * @return
	 * @throws Exception
	 */
	public String del() throws Exception{
		int flag = 0;
		String delResult;
		flag = delegate.adminDel(adminId);
		if (flag==1) {
			delResult = SUCCESS;
		}else{
			delResult = ERROR;
		}
		return delResult;
	}
	/**
	 * 添加用户
	 * @return
	 * @throws Exception
	 */
	public String add() throws Exception{
		String addResult = SUCCESS;	
		addFlag = delegate.adminAdd(admin);
		if (addFlag==1) {
			addResult = SUCCESS;
		}else{
			addResult = ERROR;
		}
		return addResult;
	}
	/**
	 * 获取所有用户
	 * @return
	 * @throws Exception
	 */
	public String getAllAdmin() throws Exception{
		adminList = delegate.getAllAdmin();
		stations = delegate.getManagementStation();
		return SUCCESS;
	}
	/**
	 * 获取单个用户
	 * @return
	 * @throws Exception
	 */
	public String getAdminById() throws Exception{
		System.out.println(adminId);
		admin = delegate.getAdminById(adminId);
		System.out.println(admin.getAdminName());
		stations = delegate.getManagementStation();
		return SUCCESS;
	}
	/**
	 * 激活用户
	 * @return
	 * @throws Exception
	 */
	public String setEnabled() throws Exception{
		int flag;
		flag = delegate.setEnabled(isEnabled, adminId);
		return SUCCESS;
	}
	
	public Integer getIsEnabled() {
		return isEnabled;
	}

	public void setIsEnabled(Integer isEnabled) {
		this.isEnabled = isEnabled;
	}

	public int getAddFlag() {
		return addFlag;
	}

	public void setAddFlag(int addFlag) {
		this.addFlag = addFlag;
	}

	public Integer getAdminId() {
		return adminId;
	}

	public void setAdminId(Integer adminId) {
		this.adminId = adminId;
	}

	public Admin getAdmin() {
		return admin;
	}

	public void setAdmin(Admin admin) {
		this.admin = admin;
	}

	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}
	
	public List<Admin> getAdminList() {
		return adminList;
	}
	public void setAdminList(List<Admin> adminList) {
		this.adminList = adminList;
	}
	public List<ManagementStation> getStations() {
		return stations;
	}
	public void setStations(List<ManagementStation> stations) {
		this.stations = stations;
	}
}
